{% extends 'base.html' %}

{% block title %}项目列表 - EasyTesting{% endblock %}

{% block header %}项目列表{% endblock %}

{% block header_buttons %}
<a href="{% url 'project_create' %}" class="btn btn-primary">
    <i class="bi bi-plus-lg"></i> 新增项目
</a>
{% endblock %}

{% block content %}
<div class="card">
    <div class="card-body">


        <div class="table-responsive">
            <table class="table table-hover">
                <thead>
                    <tr>
                        <th>名称</th>
                        <th>描述</th>
                        <th>创建人</th>
                        <th>创建时间</th>
                        <th class="text-end">操作</th>
                    </tr>
                </thead>
                <tbody>
                    {% for project in projects %}
                        <tr>
                            <td>
                                <a href="{% url 'project_detail' pk=project.pk %}" class="fw-medium text-decoration-none text-dark">
                                    {{ project.name }}
                                </a>
                            </td>
                            <td>{{ project.description|truncatechars:50 }}</td>
                            <td>
                                <div class="d-flex align-items-center">
                                    <span class="avatar avatar-sm bg-primary rounded-circle me-2 d-flex align-items-center justify-content-center" style="width: 30px; height: 30px;">
                                        {{ project.created_by.username|first|upper }}
                                    </span>
                                    <span>{{ project.created_by.username }}</span>
                                </div>
                            </td>
                            <td>{{ project.created_at|date:"Y-m-d H:i" }}</td>
                            <td class="text-end">
                                <div class="btn-group">
                                    <a href="{% url 'project_detail' pk=project.pk %}" class="btn btn-sm btn-outline-primary">
                                        <i class="bi bi-eye"></i>
                                    </a>
                                    <a href="{% url 'project_edit' pk=project.pk %}" class="btn btn-sm btn-outline-secondary">
                                        <i class="bi bi-pencil"></i>
                                    </a>
                                    <a href="{% url 'project_delete' pk=project.pk %}" class="btn btn-sm btn-outline-danger">
                                        <i class="bi bi-trash"></i>
                                    </a>
                                </div>
                            </td>
                        </tr>
                    {% empty %}
                        <tr>
                            <td colspan="5" class="text-center py-5">
                                <div class="py-5">
                                    <i class="bi bi-folder-x display-4 text-muted mb-3"></i>
                                    <h5>没有项目</h5>
                                    <p class="text-muted">创建你的第一个项目吧</p>
                                    <a href="{% url 'project_create' %}" class="btn btn-primary mt-2">
                                        <i class="bi bi-plus-lg"></i> 新增项目
                                    </a>
                                </div>
                            </td>
                        </tr>
                    {% endfor %}
                </tbody>
            </table>
        </div>

        {% include 'pagination.html' with page_obj=projects %}
    </div>
</div>

{% endblock %}
